package com.yalonga.dc.examples.r2dbc.configuration;

import com.github.jasync.sql.db.QueryResult;
import com.github.jasync.sql.db.interceptor.PreparedStatementParams;
import com.github.jasync.sql.db.interceptor.QueryInterceptor;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.concurrent.CompletableFuture;

/**
 * Created on 2023/10/13.
 *
 * @author yaolong
 * @description SqlLoggingInterceptorSupplier
 */
@Component
public class SqlLoggingInterceptorSupplier implements QueryInterceptor {
    private Logger logger = LoggerFactory.getLogger(SqlLoggingInterceptorSupplier.class);
    @NotNull
    @Override
    public PreparedStatementParams interceptPreparedStatement(@NotNull PreparedStatementParams preparedStatementParams) {
        logger.debug("preparedStatement: {}",preparedStatementParams);
        return preparedStatementParams;
    }

    @NotNull
    @Override
    public CompletableFuture<QueryResult> interceptPreparedStatementComplete(@NotNull CompletableFuture<QueryResult> completableFuture) {
        return completableFuture;
    }
    @NotNull
    @Override
    public String interceptQuery(@NotNull String s) {
        logger.debug( "sendQuery: {}",s );
        return s;
    }

    @NotNull
    @Override
    public CompletableFuture<QueryResult> interceptQueryComplete(@NotNull CompletableFuture<QueryResult> completableFuture) {
        return completableFuture;
    }
}
